<?php

class Admin_ComentarioController extends Zend_Controller_Action
{

    private $_comentarioModelo;
    private $_settings;

    public function init()
    {
        $this->_settings = Zend_Registry::get('settings');
        $this->_helper->layout->setLayout('admin');



        $this->view->headLink()->appendStylesheet('/css/layout.css');
        $this->view->headScript()->appendFile('/js/jquery-1.3.2.min.js');
        $this->view->headScript()->appendFile('/js/easyTooltip.js');
        $this->view->headScript()->appendFile('/js/jquery-ui-1.7.2.custom.min.js');


        $this->view->headScript()->appendFile('/js/hoverIntent.js');
        $this->view->headScript()->appendFile('/js/superfish.js');

        $this->view->headScript()->appendFile('/js/jquery.alerts.js');
        $this->view->headLink()->appendStylesheet('/css/jquery.alerts.css');

        $this->view->headScript()->appendFile('/js/jquery.filestyle.mini.js');
        $this->view->headScript()->appendFile('/js/custom.js');

        $this->_comentarioModelo = new admin_Model_ComentarioMapper();
    }

    public function preDispatch()
    {
        if (admin_Model_Login::isLoggedIn()) {
                    $this->view->loggedIn = true;
                    $this->_administrador = admin_Model_Login::getIdentity();
                } else {
                    $this->_redirect('/admin/login/');
                }
    }

       public function indexAction()
    {

        $pagina = $this->_getParam('pagina', 1);
        $itemsPorPagina = $this->_settings->admin->pag->itemsPagina;
	$rangoPaginado  = $this->_settings->admin->pag->rangoPagina;

        $comentarios = $this->_comentarioModelo->obtenerTodos();

        $paginator = Zend_Paginator::factory($comentarios);
        $paginator->setItemCountPerPage($itemsPorPagina)
                  ->setCurrentPageNumber($pagina)
	          ->setPageRange($rangoPaginado);

        Zend_Paginator::setDefaultScrollingStyle('Sliding');
	Zend_View_Helper_PaginationControl::setDefaultViewPartial('control_paginado.phtml');

        $this->view->headTitle('Revisión de Comentarios');
        $this->view->titulo = 'Revisión de Comentarios';

        $this->view->paginator   = $paginator;
        $this->view->comentarios = $paginator;

        $this->view->administrador = $this->_administrador;

    }

    public function eliminarAction()
    {
        $id   = (int) $this->_request->getParam('id',0);
        $this->_comentarioModelo->eliminar($id);
        $this->_redirect('/admin/comentario/');
    }



}

